#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:zhuyan
@file: threading_semaphore.py
@time: 2018/08/23
"""
from threading import Thread, currentThread, Semaphore
import time


class SemaphoreTest(Thread):

    def __init__(self):
        self.max_source = 5
        self.res_sema = Semaphore(value=self.max_source)

    def run(self):
        while 1:
            self.res_sema.acquire()
            print("AAAAAAAAAAAAAAAAA", currentThread())
            time.sleep(1)
            self.res_sema.release()
            # time.sleep(2)


if __name__ == '__main__':
    for i in range(20):
        test = SemaphoreTest()
        test.run()


